package com.yxw.yx_hotel.controller;

import com.yxw.yx_hotel.dto.PostDTO;
import com.yxw.yx_hotel.dto.PostDeleteDTO;
import com.yxw.yx_hotel.dto.PostQueryDTO;
import com.yxw.yx_hotel.service.IPostService;
import com.yxw.yx_hotel.vo.PostVO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位管理Controller控制层处理
 *
 * @author xiexuxin
 * @date 2023-09-17
 */

@Slf4j
@Api(value = "岗位管理", tags = "岗位管理")
@RestController
@Validated
@RequestMapping("/api/post")
public class PostController {

    @Autowired
    private IPostService postService;

    /**
     * 新增岗位
     */
    @ApiOperation("添加岗位")
    @PostMapping("add_post")
    public BaseResult add(@RequestBody @Validated PostDTO postDTO) {
        log.info("开始处理【添加岗位】的请求，参数：{}", postDTO);
        postService.addPost(postDTO);
        return BaseResult.success();
    }

    /**
     * 删除岗位
     */
    @ApiOperation("删除岗位")
    @PostMapping("/batch_delete")
    public BaseResult batchDelete(@RequestBody @Validated PostDeleteDTO dto) {
        log.info("开始处理【根据id批量删除岗位】的请求，参数：{}", dto);
        postService.deleteByPostIds(dto);
        return BaseResult.success();
    }

    /**
     * 修改岗位
     */
    @ApiOperation("根据id修改岗位")
    @PostMapping("/update")
    public BaseResult edit(@RequestBody @Validated PostDTO postDTO) {
        log.info("开始处理【根据id修改岗位】的请求，新数据：{}", postDTO);
        postService.updatePost(postDTO);
        return BaseResult.success();
    }

    /**
     * 根据id查询岗位信息
     */
    @ApiOperation(value = "根据id查询岗位信息")
    @GetMapping(value = "/select_post")
    public BaseResult getInfo(@RequestParam("postId") Long postId) {
        log.info("开始处理【根据id查询岗位信息】的请求，ID：{}", postId);
        PostVO postVO = postService.selectPostById(postId);
        return BaseResult.success(postVO);
    }

    /**
     * 根据部门查询岗位
     */
    @ApiOperation(value = "根据部门查询岗位")
    @GetMapping(value = "/get_post_by_dept")
    public BaseResult getPostByDept(@RequestParam("deptId") Long deptId) {
        log.info("开始处理【根据id查询岗位信息】的请求，ID：{}", deptId);
        List<PostVO> postVO = postService.getPostByDept(deptId);
        return BaseResult.success(postVO);
    }

    /**
     * 查询岗位列表
     */
    @ApiOperation(value = "查询岗位列表")
    @PostMapping("/post_list")
    public BaseResult postList() {
        log.info("开始处理【查询岗位列表】请求,无参数");
        List<PostVO> list = postService.postList();
        return BaseResult.success(list);
    }

    /**
     * 条件查询岗位列表
     */
    @ApiOperation(value = "条件查询岗位")
    @PostMapping(value = "/get_post_list")
    public BaseResult<PageVO<PostVO>> getPostList(@RequestBody PostQueryDTO postQueryDTO) {
        log.info("开始处理【条件查询岗位】请求,参数:{}", postQueryDTO);
        PageVO<PostVO> pageVo = postService.getPostList(postQueryDTO);
        return ResultHelper.fillWithSuccess(pageVo);
    }
}
